package com.cdtye.shuoh.service.product.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cdtye.shuoh.domain.product.entity.ProductCommands;
import com.cdtye.shuoh.mapper.product.ProductCommandsMapper;
import com.cdtye.shuoh.service.product.ProductCommandsRequestsService;
import com.cdtye.shuoh.service.product.ProductCommandsResponseService;
import com.cdtye.shuoh.service.product.ProductCommandsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProductCommandsServiceImpl extends ServiceImpl<ProductCommandsMapper, ProductCommands> implements ProductCommandsService {
    @Autowired
    private ProductCommandsMapper productCommandsMapper;

    @Autowired
    private ProductCommandsResponseService productCommandsResponseService;

    @Autowired
    private ProductCommandsRequestsService productCommandsResquestsService;

    @Override
    public int deleteByServiceId(String serviceId) {
        if(null!=serviceId){
            ProductCommands productCommands = productCommandsMapper.findOneByServiceId(serviceId);
            if(null!=productCommands && null!=productCommands.getId()){
                productCommandsResquestsService.deleteByCommandId(productCommands.getId());
                productCommandsResponseService.deleteByCommandId(productCommands.getId());
            }
            productCommandsMapper.deleteByServiceId(serviceId);
        }
        return 0;
    }

    @Override
    public ProductCommands findOneByServiceId(String serviceId) {
        return productCommandsMapper.findOneByServiceId(serviceId);
    }
}
